package androidserver.matlabprocessor.matlabclient;

import java.rmi.Naming;

import androidserver.exceptions.MyJSONException;
import androidserver.matlabprocessor.remote.IMatlabRemote;


public class MatlabImageProcessor {
	private String rmiRemoteObjName = "//localhost/Compute";
    
    public String processMatlabRequest(String command, int returnCount) throws MyJSONException{
    	long t1 = System.currentTimeMillis();
    	String recognizedText = "";

        try {
            IMatlabRemote comp = (IMatlabRemote) Naming.lookup(rmiRemoteObjName);
            
            recognizedText = comp.processMatlabQuery(command, returnCount);
        } catch (Exception e) {
            System.err.println("MatlabImageProcessor: " + 
                               e.getMessage());
            e.printStackTrace();
            throw new MyJSONException(MyJSONException.RMI_ERROR);
        }
        long t2 = System.currentTimeMillis();
    	System.out.println("total matlab process time (ms) - " + (t2-t1));
    	return recognizedText;
    }
}